package com.techventus.locations;

import java.util.ArrayList;

import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

@SuppressWarnings("unchecked")
public class HelloItemizedOverlay extends ItemizedOverlay {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private LocationMap origin;
	private GeoPoint geopoint;
	
	public HelloItemizedOverlay(Drawable defaultMarker){
		super(boundCenterBottom(defaultMarker));
	}
	
	public HelloItemizedOverlay(Drawable defaultMarker,LocationMap locationMap) {
		super(boundCenterBottom(defaultMarker));
		origin =locationMap;
		
	}
	public void addOverlay(OverlayItem overlay) {
		//mOverlays.set(0, overlay);
	    mOverlays.add(overlay);
	    geopoint = overlay.getPoint();
	    
	    populate();
	}
	

	
	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}
	@Override
	public int size() {
	
		return mOverlays.size();
	}
	
	@Override
	public boolean onTap(int index){
		
		Toast.makeText(origin,mOverlays.get(index).getSnippet(),Toast.LENGTH_SHORT).show();
		
		
		return(true);
	}
	
	@Override
	public boolean onTap(GeoPoint p,MapView mapView){
		//Toast.makeText(origin,"ITEM OVERLAY TAPPED",Toast.LENGTH_SHORT).show();
		//mOverlays.remove(mOverlays.size()-1);
		mOverlays.set(0, new OverlayItem(p, "SnipTitle", "SnipX"));
		
		geopoint = p;
		origin.point = geopoint;
		populate();
		Toast.makeText(origin,""+p.getLatitudeE6()+","+p.getLongitudeE6(),Toast.LENGTH_SHORT);
		
		//this.addOverlay(new OverlayItem(p, "SnipTitle", "Snip"+hio.size()+1));
		return true;
	}
	
	public GeoPoint getGeoPoint(){
		return geopoint;
	}
	
	

}
